﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;

namespace SnowLotus.Canvas
{
    public class SL2Rect:SL2Base
    {
        private Rectangle mrect;
        private TranslateTransform mtransform;
        public Rectangle Shape
        {
            get { return mrect; }
        }
        public SL2Rect(double width = 0, double height = 0, double strokeThickness = 1, Brush stroke = null, Brush fill = null)
        {
            mrect = new Rectangle();
            Manager.AddShape(mrect);
            mtransform = new TranslateTransform();
            mtransform.X = 0;
            mtransform.Y=0;
            mrect.RenderTransform = mtransform;
            mrect.Width = width;
            if(height == 0) 
                mrect.Height = width;

            mrect.StrokeThickness = strokeThickness;
            // 设置默认的 Stroke
            if (stroke != null)
            {
                mrect.Stroke = stroke;
            }
            else
            {
                mrect.Stroke = Brushes.Black;
            }
            if (fill != null)
            {
                mrect.Fill = fill;
            }
            else
            {
                mrect.Fill = Brushes.Transparent;
            }
           
        }
        public void setWidth(double width)
        {
            mrect.Width = width;
        }
        public void setHeight(double height)
        {
            mrect.Height = height;
        }

      
        public void setStrokeThickness(double strokeThickness)
        {
            mrect.StrokeThickness = strokeThickness;
        }
        public void setStroke(Brush stroke)
        {
            mrect.Stroke = stroke;
        }
        public void setFill(Brush fill)
        {
            mrect.Fill = fill;
        }
        public void setRadiusX(double radiusX)
        {
            mrect.RadiusX = radiusX;
        }
        public void setRadiusY(double radiusY)
        {
            mrect.RadiusY = radiusY;
        }
        public void setCornerRadius(double radiusX, double radiusY)
        {
            mrect.RadiusX = radiusX;
            mrect.RadiusY = radiusY;
        }
        public void setCornerRadius(double radius)
        {
            mrect.RadiusX = radius;
            mrect.RadiusY = radius;
        }


        public void move(double mx, double my)
        {
            System.Windows.Controls.Canvas.SetLeft(mrect, mx);
            System.Windows.Controls.Canvas.SetTop(mrect, my);
        }
    }
}
